//
//  OneClubeViewController.m
//  MagazineShangejie
//
//  Created by wen on 15/9/30.
//  Copyright © 2015年 CnbizMedia. All rights reserved.
//

#import "OneClubeViewController.h"
#import "Util.h"
#import "DiscoveryTableView.h"
#import "HeightCellTableViewCell.h"
#import "UMSocial.h"
@interface OneClubeViewController (){
    NSMutableDictionary*dic_m;
    
    UIView*headerView;
    NSMutableArray*headerButtons;
    NSMutableArray*userData;
    
    
    IBOutlet UITableView *theTableView;
    __weak IBOutlet UITableView *questionTableView;
    //    __weak IBOutlet UITableViewCell *higCell;
    
    NSDictionary *wordDic;
    NSArray *titleArray;
    NSMutableArray *wordArray;
    
    int cellHight;
    
    UITableViewCell *cell ;
    UITableViewCell *studyCell;
    UITableViewCell *hightCell ;
    UITableViewCell *questionCell ;
    NSMutableArray  *questionDicArray;
    NSURL *shareURL;
    
    int number;
    
    NSMutableArray *cellheightArray;
    
    __weak IBOutlet UILabel *heightLabel;
    
    __weak IBOutlet UIButton *IWantButton;
    
    NSString *baoMinString;
    UIButton *baominButton;
    
    __weak IBOutlet UIImageView *backImage;
    
    
    __weak IBOutlet UILabel *selfTitle;
    
    
    __weak IBOutlet UIButton *smallAskQuBut;
    __weak IBOutlet UIButton *BlackBackButton;
    __weak IBOutlet UIButton *smallShareButton;
    
    __weak IBOutlet UIButton *whiteBackBut;
    __weak IBOutlet UIButton *pngBigBtn;
    
    UIImageView *headImage;
    UILabel *BigTitleLabel;
    UILabel *SmaTitleLabel;
    UIButton *IWantBut;
    
}


@property (nonatomic, strong) UITableViewCell *prototypeCell;

@end

@implementation OneClubeViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:animated];
    switch (number) {
        case 0:
//            self.title = @"论坛";
            [self.navigationController setNavigationBarHidden:YES animated:animated];

            break;
            
        case 1:
//            self.title = @"游学";
            [self.navigationController setNavigationBarHidden:YES animated:animated];
            break;
            
            
        case 2:
//            self.title = @"咨询";//这里分成了两个界面，一个是永道招商，一个是智放
            selfTitle.hidden = YES;
//            whiteBackBut.hidden = YES;
//            pngBigBtn.hidden = YES;
            break;
            
        case 3:
//            self.title = @"创投";
            selfTitle.hidden = YES;
//            whiteBackBut.hidden = YES;
//            pngBigBtn.hidden = YES;
            break;
            
        case 4:
//            self.title = @"咨询";//永道招商
            selfTitle.hidden = YES;
//            whiteBackBut.hidden = YES;
//            pngBigBtn.hidden = YES;
            break;
            
        case 5:
//            self.title = @"咨询";//智放
            selfTitle.hidden = YES;
//            whiteBackBut.hidden = YES;
//            pngBigBtn.hidden = YES;
            break;
            
        default:
            break;
    }
//    [self.navigationController setNavigationBarHidden:NO animated:animated];
//    self.navigationController.navigationBar.alpha=0.0;
//    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"pngBJ"] forBarMetrics:UIBarMetricsDefault];
}

//这个新添加的clueShow相比之前的从新写了一个tableView，不同的界面用不同的cel的identifier
- (void)viewDidLoad {
    [super viewDidLoad];
    
    
//    NSString *whereComeForm = [UserDefaults objectForKey:@"whereComeForm"];
//    
//    NSString *newOldYear = [UserDefaults objectForKey:@"NewYear" ];
//    if ([newOldYear isEqualToString:@"NewYear"]) {
//        //状态栏的文字颜色换成白色
//        //        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
//        
//        if ([whereComeForm isEqualToString:@"clube"]) {
//            [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
//        }
//        
//        else  {
//            [[UINavigationBar appearance] setTintColor:[UIColor redColor]];
//        }
//    }

    
    UIButton *buttonf=[UIButton buttonWithType:UIButtonTypeCustom];
    [buttonf setFrame:CGRectMake(0, 0, 22, 22)];
    [buttonf addTarget:self action:@selector(popOfDismss) forControlEvents:UIControlEventTouchUpInside];
    [buttonf setImage:[UIImage imageNamed:@"dismiss"] forState:UIControlStateNormal];
    
    NSString *whereComeForm = [UserDefaults objectForKey:@"whereComeForm"];
    NSString *newOldYear = [UserDefaults objectForKey:@"NewYear" ];
    if ([newOldYear isEqualToString:@"NewYear"]) {
        //状态栏的文字颜色换成白色
        //        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
        
        if ([whereComeForm isEqualToString:@"clube"]) {
            //            [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
            [buttonf setImage:[UIImage imageNamed:@"dismissGray"] forState:UIControlStateNormal];
        }
        
    }
    
     UIBarButtonItem*leftBarItem = [[UIBarButtonItem alloc]initWithCustomView:buttonf];
    self.navigationItem.leftBarButtonItem=leftBarItem;

    
    
    
    
    UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
    
    UIVisualEffectView *effectview = [[UIVisualEffectView alloc] initWithEffect:blur];
    
    effectview.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    
    [backImage addSubview:effectview];
    
//    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"pngBJ"] forBarMetrics:UIBarMetricsDefault];
    
    BlackBackButton.alpha = 0;
    IWantButton.alpha = 0;
    smallShareButton.alpha = 0;
    smallAskQuBut.alpha = 0;
    
    BlackBackButton.userInteractionEnabled = NO;
    IWantButton.userInteractionEnabled = NO;
    smallShareButton.userInteractionEnabled = NO;
    smallAskQuBut.userInteractionEnabled = NO;

    
    
    UINavigationBar *bar = self.navigationController.navigationBar;
    
    
    UIView *statusBarView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, bar.frame.size.width, bar.frame.size.height)];
    
    //将它的颜色设置成你所需要的，这里我选择了黑色，表示我很沉稳
    
    statusBarView.backgroundColor=[UIColor clearColor];
    
//    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"pngBJ"] forBarMetrics:UIBarMetricsDefault];
    //这里我的思路是：之前不理想的状态是状态栏颜色也变成了导航栏的颜色，但根据这种情况，反而帮助我判断出此时的状态栏也是导航栏的一部分，而状态栏文字浮于上方，因此理论上直接在导航栏上添加一个subview就是他们中间的那一层了。
    
    //推得这样的代码：
    
//    [self.navigationController.navigationBar addSubview:statusBarView];
    
    
//    self.navigationController.navigationBar.alpha = 0.0;
//      self.navigationController.fd_prefersNavigationBarHidden = YES;

    
    
    //    self.navigationController.navigationBar.backgroundColor = [UIColor colorWithHue:1 saturation:1 brightness:1 alpha:0.0];
    
    cellheightArray = [[NSMutableArray alloc] init ];
    wordArray = [[NSMutableArray alloc] init];
    titleArray = [[NSMutableArray alloc] init];
//    UINib *cellNib = [UINib nibWithNibName:@"heightXibCell" bundle:nil];
//    [theTableView registerNib:cellNib forCellReuseIdentifier:@"heightXibCell"];
    
//    UIBarButtonItem *returnButtonItem = [[UIBarButtonItem alloc] init];
//    returnButtonItem.title = @"";
//    self.navigationItem.backBarButtonItem = returnButtonItem;
//    self.navigationItem.backBarButtonItem.tintColor = [UIColor whiteColor];
//    [self.navigationItem.backBarButtonItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],UITextAttributeTextColor,nil]];
    
    ////添加返回手势
    UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(popOfDismss)];
    [recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
    [[self view] addGestureRecognizer:recognizer];

    
    
    
    
    self.prototypeCell  = [theTableView dequeueReusableCellWithIdentifier:@"heightXibCell"];
    
    [SVProgressHUD showWithStatus:@"数据加载中..." maskType:SVProgressHUDMaskTypeClear];
    
    NSLog(@"[_scrollAnchorView.frame.origin.y ]%@",self.navigationController ) ;
    
    
    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
    
    
    baominButton = [[UIButton alloc]initWithFrame:CGRectMake(0, self.view.frame.size.height-50, self.view.frame.size.width, 50)];
    [baominButton addTarget:self action:@selector(WriteBaoMin) forControlEvents:UIControlEventTouchUpInside];
    baominButton.backgroundColor = [UIColor orangeColor];
//    baominButton.titleLabel.text = @"我要咨询";
     [baominButton setTitle:@"我要咨询" forState:UIControlStateNormal];//设置button的title
//    [self.view addSubview:baominButton];
    
    //2. 取出数据
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    number = [userDefault integerForKey:@"buttonTagNumber"];
    
    switch (number) {
        case 0:
            self.title = @"论坛";
//            selfTitle.text = @"论坛";
            titleArray = @[@"活动介绍"];
//            IWantButton.titleLabel.text = @"我要报名";
            
            [IWantButton setTitle:@"我要报名" forState:UIControlStateNormal];//设置button的title
            NSLog(@"wordArray -- %@",wordArray);
            break;
            
        case 1:
            self.title = @"游学";
//            selfTitle.text = @"游学";
            titleArray = @[@"行程特色",@"行程安排"];//
//            IWantButton.titleLabel.text = @"我要报名";
       
            [IWantButton setTitle:@"我要报名" forState:UIControlStateNormal];//设置button的title
            break;
            
        case 2:
            self.title = @"咨询";//这里分成了两个界面，一个是永道招商，一个是智放
//            selfTitle.text = @"咨询";
//            IWantButton.titleLabel.text = @"我要咨询";
           
            [IWantButton setTitle:@"我要咨询" forState:UIControlStateNormal];//设置button的title
            break;
            
        case 3:
            self.title = @"创投";
//            selfTitle.text = @"创投";
            titleArray = @[@"项目简介",@"核心优势",@"融资进度",@"目前规模",@"未来预期"];//   核心优势  融资进度  目前规模  未来预期
//            IWantButton.titleLabel.text = @"我要投资";
           
            [IWantButton setTitle:@"我要投资" forState:UIControlStateNormal];//设置button的title
            break;
            
        case 4:
            self.title = @"咨询";//永道招商
//            selfTitle.text = @"咨询";
            titleArray = @[@"项目概况",@"品牌述求",@"策略回顾",@"效果总结"];//
//            IWantButton.titleLabel.text = @"我要咨询";
     
            [IWantButton setTitle:@"我要咨询" forState:UIControlStateNormal];//设置button的title
            break;
            
        case 5:
            self.title = @"咨询";//智放
//            selfTitle.text = @"咨询";
            titleArray = @[@"项目概况",@"挑战来袭",@"突围之道",@"丰硕成果"];//
//            IWantButton.titleLabel.text = @"我要咨询";
  
            [IWantButton setTitle:@"我要咨询" forState:UIControlStateNormal];//设置button的title
            break;
            
        default:
            break;
    }
    
    
    
    
    
    
    
    NSDictionary *lunTanDic = [userDefault objectForKey:@"lunTanDic"];
    baoMinString =[lunTanDic objectForKey:@"groupids_view"];
    
    NSString *idString = [lunTanDic objectForKey:@"id"];
    NSString *catid    = [lunTanDic objectForKey:@"catid"];
    
    NSDictionary *parameter=@{@"catid":catid,@"id":idString};
    
    [[AppAPIClient sharedClient] GET:@"Club/Show" parameters:parameter success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"operation = =%@",operation);
//        shareURL = operation.request.URL;
        
        
        
        NSMutableDictionary *result = responseObject[@"data"];
        NSLog(@"luntan-data == %@",result);
        if([result isKindOfClass:[NSNull class]] || [result count] == 0){
            return;
        }
        if([result isKindOfClass:[NSNull class]] || [result count] == 0||[result[@"content"] count]==0){
            return;
        }
        
        shareURL = result[@"content"][@"shareurl"];
        NSLog(@"shareURL -- %@",shareURL);
        
        wordDic = nil;
        
        wordDic = [[NSDictionary alloc] initWithDictionary:result[@"content"] copyItems:YES ];
        NSLog(@"wordDic -- %@",wordDic);
        
        
        questionDicArray = [[NSMutableArray alloc] initWithArray:result[@"answer"] ];
        NSLog(@"answer-questionDicArray == %@",questionDicArray);
        
        switch (number) {
            case 0:
                self.title = @"论坛";
//                selfTitle.text = @"论坛";
                titleArray = @[@"活动介绍"];
                wordArray = [[NSMutableArray alloc] initWithObjects:[wordDic objectForKey:@"info"],nil];
                NSLog(@"wordArray -- %@",wordArray);
                break;
                
            case 1:
                self.title = @"游学";
//                selfTitle.text = @"游学";
                titleArray = @[@"行程特色",@"行程安排"];//
                wordArray = [[NSMutableArray alloc] initWithObjects:[wordDic objectForKey:@"info"],[wordDic objectForKey:@"info"],nil];
                
                break;
                
            case 2:
                self.title = @"咨询";
//                selfTitle.text = @"咨询";
                titleArray = @[@"项目概括",@"品牌诉求",@"策略回顾",@"效果总结"];//这里分成了两个界面，一个是永道招商，一个是智放  gaikuang  suqiu   huigu  zongjie
                wordArray = [[NSMutableArray alloc] initWithObjects:[wordDic objectForKey:@"gaikuang"],[wordDic objectForKey:@"suqiu"],[wordDic objectForKey:@"huigu"],[wordDic objectForKey:@"zongjie"],nil];
                NSLog(@"wordArray %@",wordArray);
                break;
                
            case 3:
                self.title = @"创投";
//                selfTitle.text = @"创投";
                titleArray = @[@"项目简介",@"核心优势",@"融资进度",@"目前规模",@"未来预期"];//   核心优势  融资进度  目前规模  未来预期
                wordArray = [[NSMutableArray alloc] initWithObjects:[wordDic objectForKey:@"description"],[wordDic objectForKey:@"advantage"],[wordDic objectForKey:@"financingprogress"],[wordDic objectForKey:@"scale"],[wordDic objectForKey:@"expect"],nil];//
                
                break;
                
            case 4:
                self.title = @"咨询";//永道招商
//                selfTitle.text = @"咨询";
                titleArray = @[@"项目概括",@"品牌诉求",@"策略回顾",@"效果总结"];//这里分成了两个界面，一个是永道招商，一个是智放  gaikuang  suqiu   huigu  zongjie
                wordArray = [[NSMutableArray alloc] initWithObjects:[wordDic objectForKey:@"gaikuang"],[wordDic objectForKey:@"suqiu"],[wordDic objectForKey:@"huigu"],[wordDic objectForKey:@"zongjie"],nil];
                NSLog(@"wordArray %@",wordArray);
                break;
                
            case 5:
                self.title = @"咨询";//智放
//                selfTitle.text = @"咨询";
                titleArray = @[@"项目概括",@"品牌诉求",@"策略回顾",@"效果总结"];//这里分成了两个界面，一个是永道招商，一个是智放  gaikuang  suqiu   huigu  zongjie
                wordArray = [[NSMutableArray alloc] initWithObjects:[wordDic objectForKey:@"gaikuang"],[wordDic objectForKey:@"suqiu"],[wordDic objectForKey:@"huigu"],[wordDic objectForKey:@"zongjie"],nil];
                NSLog(@"wordArray %@",wordArray);
                break;
                
            default:
                break;
        }
        
        self->theTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        self->theTableView.separatorStyle = NO;
        
        //        theTableView.estimatedRowHeight = 44;
        //        theTableView.rowHeight = UITableViewAutomaticDimension;
        
        [theTableView reloadData];
        
        [SVProgressHUD dismiss];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
    
    [self setRightBarButton];
    
    self->theTableView.delaysContentTouches = NO;
    
    theTableView.backgroundColor = [UIColor clearColor];
//    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    NSInteger number = [userDefault integerForKey:@"underBarShow"];
    
    if (number == 1) {
        //设置通知，显示tabbar
        [[NSNotificationCenter defaultCenter] postNotificationName:@"showBootomBar" object:self userInfo:nil ];
    }
}

- (void)setRightBarButton
{
//    UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
//    [button setImage:[UIImage imageNamed:@"share01"] forState:UIControlStateNormal];
//    [button setFrame:CGRectMake(0, 0, 25, 25)];
//    [button addTarget:self action:@selector(rightBarButtonClicked) forControlEvents:UIControlEventTouchUpInside];
//    UIBarButtonItem*rightItem = [[UIBarButtonItem alloc]initWithCustomView:button];
//    
//    self.navigationItem.rightBarButtonItem= rightItem;
}

//分享按钮

- (void)rightBarButtonClicked
{
    
    NSString *URLString = [NSString stringWithFormat:@"%@",shareURL];
    UIImageView*imageview=[[UIImageView alloc]init];
    [imageview sd_setImageWithURL:[NSURL URLWithString:wordDic[@"thumb2"]]];
    
    
    UIImage *shareImage = [[UIImage alloc]init];

    BDSocialShareContent *content = [BDSocialShareContent shareContentWithDescription:[wordDic objectForKey:@"title"] url:URLString title:@"看商界"];
    [content addImageWithThumbImage:shareImage imageUrl:[NSString stringWithFormat:@"%@",wordDic[@"thumb2"]]];
    
//    [imageview sd_setImageWithURL:[NSURL URLWithString:wordDic[@"thumb2"]] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
//        if (image==nil) {
//            [content addImageWithThumbImage:[UIImage imageNamed:@"icon_default_ipad"] imageSource:[UIImage imageNamed:@"icon_default_ipad"]];
//        }else{
//            [content addImageWithThumbImage:image imageSource:image];
//        }
    
//    imageview.image=[UIImage imageNamed:@"icon"];
    [SVProgressHUD dismiss];
    //分享
    [UMSocialSnsService presentSnsIconSheetView:self
                                         appKey:nil
                                      shareText:[NSString stringWithFormat:@"%@%@",[wordDic objectForKey:@"title"],URLString]
                                     shareImage:imageview.image
                                shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToQQ,UMShareToQzone,UMShareToWechatTimeline,UMShareToWechatSession,UMShareToTencent,UMShareToEmail,UMShareToSms,nil]
                                       delegate:self];
    
    [UMSocialData defaultData].extConfig.sinaData.urlResource.url = URLString;
    [UMSocialData defaultData].extConfig.qqData.url = URLString;
    [UMSocialData defaultData].extConfig.qzoneData.url = URLString;
    [UMSocialData defaultData].extConfig.wechatTimelineData.url = URLString;
    [UMSocialData defaultData].extConfig.wechatSessionData.url = URLString;
    
    [UMSocialConfig hiddenNotInstallPlatforms:@[UMShareToQQ,UMShareToQzone,UMShareToWechatSession,UMShareToWechatTimeline]];
     
    
}

-(void)didSelectSocialPlatform:(NSString *)platformName withSocialData:(UMSocialData *)socialData
{
//    if (platformName == UMShareToSina) {
//        socialData.shareText = [NSString stringWithFormat:@"%@ %@",[wordDic objectForKey:@"title"],shareURL ];
//    }
//    else{
//        socialData.shareText = [NSString stringWithFormat:@"%@",[wordDic objectForKey:@"title"]  ];
//    }
//    
    
    if (platformName == UMShareToSina) {
        socialData.shareText = [NSString stringWithFormat:@"%@ %@",[wordDic objectForKey:@"title"],shareURL];
    }
    else{
        socialData.shareText = [NSString stringWithFormat:@"%@",[wordDic objectForKey:@"title"]];
        
        
        //        QQ设置title方法为
        NSString *URLString = [NSString stringWithFormat:@"%@",shareURL];
//        [UMSocialData defaultData].extConfig.qqData.title = [NSString stringWithFormat:@"QQ好友分享%@%@",[wordDic objectForKey:@"title"],URLString];
        
        //        Qzone设置title方法将平台参数名替换即可
        
        [UMSocialData defaultData].extConfig.qzoneData.title = [wordDic objectForKey:@"title"];
        
        
        
        //        设置微信好友title方法为
        
        [UMSocialData defaultData].extConfig.wechatSessionData.title = [wordDic objectForKey:@"title"] ;
        
        //        设置微信朋友圈title方法替换平台参数名即可
        
        [UMSocialData defaultData].extConfig.wechatTimelineData.title = [wordDic objectForKey:@"title"];
        
    }

}

- (void)didReceiveMemoryWarning {
    

    
    [SVProgressHUD dismiss];
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    if ([tableView isEqual:theTableView]) {
        return 5;
    }
    //    else if([tableView isEqual: questionTableView ]){
    //        return 1;
    //    }
    return 0;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    if ([tableView isEqual:theTableView]) {
        if (section==0) {
            return 1;
        }else if (section==1){
            NSLog(@"wordArray %@",wordArray);
            return wordArray.count;
        }else if (section==2){
            //        return 2;
            return 1;
        }
        else if (section==3){
            return questionDicArray.count;
        }
//        else if (section==4){
//            return 1;
//        }
        
        else{
            return 0;
        }
    }
    
    //    else if([tableView isEqual: questionTableView ]){
    //        return questionDicArray.count;
    //    }
    //    else {
    return 0;
    //    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    //    if ([tableView isEqual:theTableView]) {
    
    if (indexPath.section==0) {
        if ([self.title isEqualToString:@"游学"] || [self.title isEqualToString:@"论坛"] ) {
            return 300 ;//
            
        }
        else if([self.title isEqualToString:@"创投"]){
            return 220;
        }
        
        else {
            return 220;
        }
        
    }
    
    else if (indexPath.section==1){
        
        
        
        heightLabel.text = wordArray[indexPath.row];
        
        
        NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[wordArray[indexPath.row] dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
        
        heightLabel.attributedText = attrStr;
        //        wordLabel.text = wordArray[indexPath.row];
        
        [heightLabel setNumberOfLines:0];
        
        heightLabel.lineBreakMode = NSLineBreakByWordWrapping;
        
        
        
        
        
        [heightLabel setNumberOfLines:0];
        
        heightLabel.lineBreakMode = NSLineBreakByWordWrapping;
        
        NSLog(@"heightLabel.text == %@",heightLabel.text);
        NSMutableDictionary *copyDic = [ wordDic mutableCopy];
        [copyDic setObject:heightLabel.text forKey:@"chuangtouStory"];
        [UserDefaults setObject:wordDic forKey:@"titleDic"] ;
        
        UIFont *fnt = [UIFont fontWithName:@"HelveticaNeue" size:14.0f];
        heightLabel.font = fnt;
        
        NSLog(@"1heightLabel.frame.size.height == %f 1heightLabel.frame.size.width == %f",heightLabel.frame.size.height,heightLabel.frame.size.width);
        CGSize size = [heightLabel sizeThatFits:CGSizeMake(300, MAXFLOAT)];
        
        heightLabel.frame =CGRectMake(heightLabel.frame.origin.x, heightLabel.frame.origin.y, heightLabel.frame.size.width, size.height);
        heightLabel.font = [UIFont systemFontOfSize:15];
        
        NSLog(@"2heightLabel.frame.size.height == %f 2heightLabel.frame.size.width == %f",heightLabel.frame.size.height,heightLabel.frame.size.width);
        int abc = heightLabel.frame.size.height + 70;// / 20.0f  * 16
        NSLog(@"wordLabel.lineBreakMode %ld",(long)heightLabel.lineBreakMode);

        heightLabel.hidden = YES;
        
        NSLog(@"abc %d",abc);
        NSLog(@"indexPath.row %ld",(long)indexPath.row);
        return abc;

    }
    
    else if(indexPath.section==2){
        
        if (questionDicArray.count > 0) {
             return 55;
        }
       
        return 100;
    }
    
    else if(indexPath.section==3){
        
        
        NSDictionary *questionDic = questionDicArray[indexPath.row];
        NSString *replyString = [questionDic objectForKey:@"reply"];
        
        //有答复的高度
        if (replyString.length > 0) {
                    return 151;
        }

        else{
            return 77;
        }
        
    }
    else if(indexPath.section==4){
        return 49;
    }
    
    //    }
    
    //    else if([tableView isEqual: questionTableView ]){
    //        return 200;
    //    }
    
    return 0;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 0;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    //    if ([tableView isEqual:theTableView]) {
    
    for (id obj in cell.subviews)
        
    {
        
        if ([NSStringFromClass([obj class])isEqualToString:@"UITableViewCellScrollView"])
            
        {
            
            UIScrollView *scroll = (UIScrollView *) obj;
            
            scroll.delaysContentTouches =NO;
            
            break;
            
        }
        
    }
    
    if (indexPath.section==0){
        if ([self.title isEqualToString:@"游学"]) {
            
            cell = [tableView dequeueReusableCellWithIdentifier:@"studyHeadCell" forIndexPath:indexPath];
            
            if (cell==nil) {
                
                cell=[tableView dequeueReusableCellWithIdentifier:@"studyHeadCell"];
            }
            
            
            //            UIImageView *headImage;
            //            UILabel *BigTitleLabel;
            //            UILabel *SmaTitleLabel;
            //            UIButton *IWantBut;

            
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            //            cell.userInteractionEnabled = NO;
            //            UILabel*label6=(UILabel*)[cell.contentView viewWithTag:102];
            //            label6.text = @"报名人数";
            
            UILabel*label6=(UILabel*)[cell.contentView viewWithTag:102];
            label6.text = @"报名人数";
            
            
            NSMutableDictionary *copyDic = [wordDic mutableCopy];
            
//            [copyDic setObject:wordArray[0] forKey:@"chuangtouStory"];
            
            
            [UserDefaults setObject:copyDic forKey:@"titleDic"];
            
            if ([wordDic objectForKey:@"number"]) {
                label6.text = [NSString stringWithFormat:@"报名人数:%@人",[wordDic objectForKey:@"number"]];
             
            }
//             SmaTitleLabel = label6;
            
            //            UIImageView *headImage;
            //            UILabel *BigTitleLabel;
            //            UILabel *SmaTitleLabel;
            //            UIButton *IWantBut;
            
            
            
            UIImageView*imageView=(UIImageView*)[cell.contentView viewWithTag:100];
            [imageView sd_setImageWithURL:[NSURL URLWithString:wordDic[@"thumb"]]];
            headImage = imageView;
            //            UIImageView*backImageView=(UIImageView*)[cell.contentView viewWithTag:99];
            //            [backImageView sd_setImageWithURL:[NSURL URLWithString:wordDic[@"thumb2"]]];
            
//            [backImage sd_setImageWithURL:[NSURL URLWithString:wordDic[@"thumb2"]]];
            
            UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
            
            UIVisualEffectView *effectview = [[UIVisualEffectView alloc] initWithEffect:blur];
            
            
            
            
            
            
            UILabel*label2=(UILabel*)[cell.contentView viewWithTag:101];
            label2.text = @"游学标题";
            label2.text = [wordDic objectForKey:@"title"];
            BigTitleLabel = label2;
            
            UILabel*label3=(UILabel*)[cell.contentView viewWithTag:111];
            label3.text = @"地址";
            
            if ([wordDic objectForKey:@"area"]) {
                label3.text = [NSString stringWithFormat:@"%@%@",[wordDic objectForKey:@"area"],[wordDic objectForKey:@"address"] ];
            }
            
            NSLog(@"area ++++++++  address %@    %@",[wordDic objectForKey:@"area"],[wordDic objectForKey:@"address"] );
            
            UIButton *IWantButtonUP = (UIButton *)[cell.contentView viewWithTag:2211];
            [IWantButtonUP setTitle:@"+ 我要报名" forState:UIControlStateNormal];
            [IWantButtonUP addTarget:nil action:@selector(WriteBaoMin) forControlEvents:UIControlEventTouchUpInside];
            IWantBut = IWantButtonUP;
            
            [self.view addSubview:SmaTitleLabel];
//            UILabel*label4=(UILabel*)[cell.contentView viewWithTag:103];
//            label4.text = @"进行中";
            
            NSString *acc = wordDic[@"activitystatus"];
            int accc = [acc intValue];
            
            switch (accc) {
                case 1:
//                    label4.text = @"筹备中";
//                    label4.backgroundColor = [UIColor orangeColor];
                    break;
                    
                case 2:
//                    label4.text = @"进行中";
//                    label4.backgroundColor = [UIColor orangeColor];
                    break;
                    
                case 3:
//                    label4.text = @"已结束";
//                    label4.backgroundColor = [UIColor blackColor];
                    
                    [IWantButtonUP setTitle:@"已结束" forState:UIControlStateNormal];
                    IWantButtonUP.userInteractionEnabled = NO;
                    
                    
                    [IWantButton setTitle:@"已结束" forState:UIControlStateNormal];//设置button的title
                    [IWantButton setBackgroundImage:[UIImage imageNamed:@"TimeOut"] forState:UIControlStateNormal];
                    
                    IWantButton.userInteractionEnabled = NO;
                    break;
                    
                default:
                    break;
            }
            
            NSString *timeString = [wordDic objectForKey:@"inputtime"];
            
            NSLog(@"timeString -- %@",timeString);
            //得到运动时间，需要转成年月日
            
            NSDateFormatter * formatter = [[NSDateFormatter alloc ] init];
            [formatter setDateFormat:@"YYYY-MM-dd"];
            NSString *date =  [formatter stringFromDate:[NSDate date]];
            NSString *timeLocal = [[NSString alloc] initWithFormat:@"%@", date];
            NSLog(@"timeLocal%@", timeLocal);
            
            
            
            UILabel*label8=(UILabel*)[cell.contentView viewWithTag:211];
            label8.text = wordDic[@"activitytime" ];
            
            
            cell.backgroundColor = UIColorFromRGB(0xf5f5f5);
            cell.backgroundColor = UIColorFromRGBWithAlpha(1, 0);
            
            UIButton *backButton=(UIButton*)[cell.contentView viewWithTag:889];
            [backButton addTarget:self action:@selector(popOfDismss) forControlEvents:UIControlEventTouchUpInside];
            
            return cell;
            
            
        }
        
        
        else if ([self.title isEqualToString:@"论坛"]){
            
            cell = [tableView dequeueReusableCellWithIdentifier:@"studyHeadCell" forIndexPath:indexPath];
            if (cell==nil) {
                cell=[tableView dequeueReusableCellWithIdentifier:@"studyHeadCell"];
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            UILabel*label6=(UILabel*)[cell.contentView viewWithTag:102];
            label6.text = @"参与人数";
            if ([wordDic objectForKey:@"number"]) {
                label6.text = [NSString stringWithFormat:@"参与人数:%@人",[wordDic objectForKey:@"number"]];
                SmaTitleLabel = label6;
            }
            
            
            NSMutableDictionary *copyDic = [wordDic mutableCopy];
            
            //            [copyDic setObject:wordArray[0] forKey:@"chuangtouStory"];
            
            
            [UserDefaults setObject:copyDic forKey:@"titleDic"];
            
//            UIImageView *headImage;
            //            UILabel *BigTitleLabel;
            //            UILabel *SmaTitleLabel;
            //            UIButton *IWantBut;
            
            UIImageView*imageView=(UIImageView*)[cell.contentView viewWithTag:100];
            [imageView sd_setImageWithURL:[NSURL URLWithString:wordDic[@"thumb"]]];
            headImage = imageView;
//            UIImageView*backImageView=(UIImageView*)[cell.contentView viewWithTag:99];
//            [backImageView sd_setImageWithURL:[NSURL URLWithString:wordDic[@"thumb2"]]];
            
//            [backImage sd_setImageWithURL:[NSURL URLWithString:wordDic[@"thumb2"]]];
          
            
            UILabel*label2=(UILabel*)[cell.contentView viewWithTag:101];
            label2.text = @"论坛标题";
            label2.text = [wordDic objectForKey:@"title"];
            BigTitleLabel = label2;
            
            UILabel*label3=(UILabel*)[cell.contentView viewWithTag:111];
            label3.text = @"地址";
            if ([wordDic objectForKey:@"area"]) {
                label3.text = [NSString stringWithFormat:@"%@%@",[wordDic objectForKey:@"area"],[wordDic objectForKey:@"address"] ];
            }
            
            UILabel*label11=(UILabel*)[cell.contentView viewWithTag:110];
            label11.text = @"活动地点:";
            
            UILabel*label22=(UILabel*)[cell.contentView viewWithTag:210];
            label22.text = @"活动时间:";

            UIButton *IWantButtonUP = (UIButton *)[cell.contentView viewWithTag:2211];
            [IWantButtonUP setTitle:@"+ 我要报名" forState:UIControlStateNormal];
            [IWantButtonUP addTarget:nil action:@selector(WriteBaoMin) forControlEvents:UIControlEventTouchUpInside];
            IWantBut = IWantButtonUP;
            
//            UILabel*label4=(UILabel*)[cell.contentView viewWithTag:103];
//            label4.text = @"进行中";
            NSString *acc = wordDic[@"activitystatus"];
            int accc = [acc intValue];
            
            switch (accc) {
                case 1:
//                    label4.text = @"筹备中";
//                    label4.backgroundColor = [UIColor orangeColor];
                    
                    break;
                    
                case 2:
//                    label4.text = @"进行中";
//                    label4.backgroundColor = [UIColor orangeColor];
                    break;
                    
                case 3:
//                    label4.text = @"已结束";
//                    label4.backgroundColor = [UIColor blackColor];
                    
                    [IWantButtonUP setTitle:@"已结束" forState:UIControlStateNormal];
                    IWantButtonUP.userInteractionEnabled = NO;
                    
                    
                    [IWantButton setTitle:@"已结束" forState:UIControlStateNormal];//设置button的title
                    [IWantButton setBackgroundImage:[UIImage imageNamed:@"TimeOut"] forState:UIControlStateNormal];
                    IWantButton.userInteractionEnabled = NO;

                    break;
                    
                default:
                    break;
            }

            NSString *timeString = [wordDic objectForKey:@"inputtime"];
            
            NSLog(@"timeString -- %@",timeString);
            //得到运动时间，需要转成年月日
            
            NSDateFormatter * formatter = [[NSDateFormatter alloc ] init];
            [formatter setDateFormat:@"YYYY-MM-dd"];
            NSString *date =  [formatter stringFromDate:[NSDate date]];
            NSString *timeLocal = [[NSString alloc] initWithFormat:@"%@", date];
            NSLog(@"timeLocal%@", timeLocal);
            
            if ([timeString integerValue] < [timeLocal integerValue]) {
//                label4.text = @"进行中";
            }
            else {
//                label4.text = @"已结束";
//                label4.backgroundColor = [UIColor blackColor];
            }
            
            UILabel*label8=(UILabel*)[cell.contentView viewWithTag:211];
            label8.text = wordDic[@"activitytime" ];
            
            cell.backgroundColor = UIColorFromRGB(0xf5f5f5);
            cell.backgroundColor = UIColorFromRGBWithAlpha(1, 0);
            
            
            UIButton *backButton=(UIButton*)[cell.contentView viewWithTag:889];
            [backButton addTarget:self action:@selector(popOfDismss) forControlEvents:UIControlEventTouchUpInside];
            
            return cell;
            
        }
        
        
        else if ([self.title isEqualToString:@"创投"]){
            
            cell = [tableView dequeueReusableCellWithIdentifier:@"chuangTouHeadCell" forIndexPath:indexPath];
            if (cell==nil) {
                cell=[tableView dequeueReusableCellWithIdentifier:@"chuangTouHeadCell"];
            }
            
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            UIImageView*imageView=(UIImageView*)[cell.contentView viewWithTag:111];
            [imageView sd_setImageWithURL:[NSURL URLWithString:wordDic[@"thumb"]]];
            
            UILabel*label2=(UILabel*)[cell.contentView viewWithTag:211];
            label2.text = @"创投标题";
            label2.text = [wordDic objectForKey:@"title"];
            
            UILabel*label3=(UILabel*)[cell.contentView viewWithTag:311];
            label3.text = @"创始人 ";
            label3.text =  [wordDic objectForKey:@"founder"]  ;
            NSString *timeString = [wordDic objectForKey:@"inputtime"];
            
            UIButton *IWantButtonUP = (UIButton *)[cell.contentView viewWithTag:2211];
//            [IWantButtonUP setTitle:@"+ 我要报名" forState:UIControlStateNormal];
            [IWantButtonUP addTarget:nil action:@selector(WriteBaoMin) forControlEvents:UIControlEventTouchUpInside];
            IWantBut = IWantButtonUP;
            
            NSString *acc = wordDic[@"financingstatus"];
            int accc = [acc intValue];
            
            switch (accc) {
                case 1:
//                    label4.text = @"融资中";
//                    label4.backgroundColor = [UIColor orangeColor];
                    
                    
//                    IWantButton.titleLabel.text = @"我要投资";
//                    
//                    
//                    IWantButton.backgroundColor = [UIColor lightGrayColor];
//                    IWantButton.userInteractionEnabled = NO;

                    break;
                    
                case 2:
//                    label4.text = @"已完成";
//                    label4.backgroundColor = [UIColor orangeColor];
                    [IWantButton setTitle:@"已结束" forState:UIControlStateNormal];//设置button的title
                    [IWantButton setBackgroundImage:[UIImage imageNamed:@"TimeOut"] forState:UIControlStateNormal];
                    IWantButton.userInteractionEnabled = NO;

                    break;
                    
                default:
                    break;
            }

            
            cell.backgroundColor = UIColorFromRGB(0xf5f5f5);
            cell.backgroundColor = UIColorFromRGBWithAlpha(1, 0);
            
            UIButton *backButton=(UIButton*)[cell.contentView viewWithTag:889];
            [backButton addTarget:self action:@selector(popOfDismss) forControlEvents:UIControlEventTouchUpInside];
            return cell;
            
        }
        
        else if ([self.title isEqualToString:@"咨询"]){
            
            cell = [tableView dequeueReusableCellWithIdentifier:@"zixunHeadViewCell" forIndexPath:indexPath];
            if (cell==nil) {
                cell=[tableView dequeueReusableCellWithIdentifier:@"zixunHeadViewCell"];
            }
            
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            UIImageView*imageView=(UIImageView*)[cell.contentView viewWithTag:11];
            [imageView sd_setImageWithURL:[NSURL URLWithString:wordDic[@"thumb"]]];
            
            UILabel*label2=(UILabel*)[cell.contentView viewWithTag:22];
            label2.text = @"项目名称:";
            if ([wordDic objectForKey:@"title"]) {
                label2.text = [NSString stringWithFormat:@"项目名称:%@",[wordDic objectForKey:@"title"]];
            }
            
            
//            IWantButton.titleLabel.text = @"我要咨询";

//            NSString *acc = wordDic[@"financingstatus"];
//            int accc = [acc intValue];
//            
//            switch (accc) {
//                case 1:
//                    //                    label4.text = @"融资中";
//                    //                    label4.backgroundColor = [UIColor orangeColor];
//                    IWantButton.titleLabel.text = @"我要咨询";
//                    //                    IWantButton.backgroundColor = [UIColor lightGrayColor];
//                    //                    IWantButton.userInteractionEnabled = NO;
//                    
//                    break;
//                    
//                case 2:
//                    //                    label4.text = @"已完成";
//                    //                    label4.backgroundColor = [UIColor orangeColor];
//                    IWantButton.titleLabel.text = @"已结束";
//                    IWantButton.backgroundColor = [UIColor lightGrayColor];
//                    IWantButton.userInteractionEnabled = NO;
//                    
//                    break;
//                    
//                default:
//                    break;
//            }

            
            //                cell.backgroundColor = UIColorFromRGB(0xf5f5f5);

            UIButton *backButton=(UIButton*)[cell.contentView viewWithTag:889];
            [backButton addTarget:self action:@selector(popOfDismss) forControlEvents:UIControlEventTouchUpInside];
            
            return cell;
            
        }
    }
    
    else if (indexPath.section == 1){
        
        cell = [tableView dequeueReusableCellWithIdentifier:@"wordCell" forIndexPath:indexPath];
        
        if (cell==nil) {
            
            cell=[tableView dequeueReusableCellWithIdentifier:@"wordCell"];
        }
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        UILabel *title = (UILabel *)[cell.contentView viewWithTag:11];
        title.text = titleArray[indexPath.row];
        
        UIImage *lineImage = (UIImage *)[cell.contentView viewWithTag:33];
        
        UILabel *wordLabel = (UILabel *)[cell.contentView viewWithTag:22];
 
        NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[wordArray[indexPath.row] dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];

        wordLabel.attributedText = attrStr;
//        wordLabel.text = wordArray[indexPath.row];
        
        [wordLabel setNumberOfLines:0];
        
        wordLabel.lineBreakMode = NSLineBreakByWordWrapping;
        
        NSLog(@"wordLabel.text == %@",wordLabel.text);
        
        UIFont *fnt = [UIFont fontWithName:@"HelveticaNeue" size:14.0f];
        wordLabel.font = fnt;
   
        NSLog(@"1wordLabel.frame.size.height == %f 1wordLabel.frame.size.width == %f",wordLabel.frame.size.height,wordLabel.frame.size.width);
        CGSize size = [wordLabel sizeThatFits:CGSizeMake(300, MAXFLOAT)];
        
        wordLabel.frame =CGRectMake(wordLabel.frame.origin.x, wordLabel.frame.origin.y, wordLabel.frame.size.width, size.height);
        wordLabel.font = [UIFont systemFontOfSize:15];
 
        NSLog(@"2wordLabel.frame.size.height == %f 2wordLabel.frame.size.width == %f",wordLabel.frame.size.height,wordLabel.frame.size.width);
        cellHight = wordLabel.frame.size.height + 60;// / 20.0f  * 16
        NSLog(@"wordLabel.lineBreakMode %ld",(long)wordLabel.lineBreakMode);
        
        
        cell.backgroundColor = UIColorFromRGB(0xf5f5f5);

        return cell;
    }
    
    
    else if (indexPath.section == 2){
        
        cell.userInteractionEnabled = YES;
        cell = [tableView dequeueReusableCellWithIdentifier:@"askQuestionCell" forIndexPath:indexPath];
        
        if (cell==nil) {
            
            cell=[tableView dequeueReusableCellWithIdentifier:@"askQuestionCell"];
        }
        
        
        UIButton *queButton = [[UIButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width-66, 21, 65, 26)];
        [queButton setImage:[UIImage imageNamed:@"p_btn"] forState:UIControlStateNormal];
        [queButton addTarget:self action:@selector(questionEvent) forControlEvents:UIControlEventTouchUpInside];
        [cell addSubview:queButton];
        
        
        
        tableView.delaysContentTouches = NO;
        
        cell.backgroundColor = UIColorFromRGB(0xf5f5f5);
        
        
        return cell;
        
    }
    
    else if (indexPath.section == 3){
        
        NSLog(@"questionDicArray -- %@",questionDicArray);
        NSDictionary *questionDic = questionDicArray[indexPath.row];
        NSString *replyString = [questionDic objectForKey:@"reply"];

        if (replyString.length > 0) {
            
            
            
            cell = [tableView dequeueReusableCellWithIdentifier:@"questionCell" forIndexPath:indexPath];
            
            if (cell==nil) {
                
                cell=[tableView dequeueReusableCellWithIdentifier:@"questionCell"];
            }
            
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            UIView *backView = (UIView *)[cell.contentView viewWithTag:1];
            backView.backgroundColor = [UIColor whiteColor];
            
            
            
            NSLog(@"questionDic -- %@",questionDic);
            UILabel*label1=(UILabel*)[cell.contentView viewWithTag:111];
            label1.text = @"188***21";
            label1.text = [questionDic objectForKey:@"name"];
            
            //           reply introduce
            UILabel*label2=(UILabel*)[cell.contentView viewWithTag:222];
            label2.text = @"问题";
            label2.text = [questionDic objectForKey:@"introduce"];
            NSLog(@"[questionDic objectForKey:@introduce]%@",[questionDic objectForKey:@"introduce"]);
            label2.numberOfLines = 0;
            [label2 sizeToFit];

            
            UILabel*label4=(UILabel*)[cell.contentView viewWithTag:555];
            label4.text = @"回答";
            label4.text = [questionDic objectForKey:@"reply"];
            label4.numberOfLines = 0;
            [label4 sizeToFit];
            NSLog(@"[questionDic objectForKey:@reply]%@",[questionDic objectForKey:@"reply"]);
            
            UILabel*label3=(UILabel*)[cell.contentView viewWithTag:333];
            label3.text = @"2015-1-12";
            
            UILabel*label5=(UILabel*)[cell.contentView viewWithTag:666];
            label5.text = @"2015-1-12";
            
            NSString *timeString = [questionDic objectForKey:@"addtime"];
            
            NSLog(@"timeString -- %@",timeString);
            //得到运动时间，需要转成年月日
            NSString *formatString = @"YYYY-MM-dd";
            
            NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
            [dateFormat setDateFormat:formatString];
            NSDate*confromTimesp = [NSDate dateWithTimeIntervalSince1970:(NSTimeInterval)[timeString intValue] - 28800];
            NSString *dateString =[NSString stringWithFormat:@"%@",[dateFormat stringFromDate:confromTimesp] ];
            NSLog(@"date: %@", dateString);
            
            label3.text = dateString;
            label5.text = dateString;

            return cell;

        }

        
        //        cell.userInteractionEnabled = NO;
        
//        UIImageView *view = (UIImageView *)[cell.contentView viewWithTag:444];
//        view.backgroundColor = [UIColor grayColor];
 
        else {
        
            cell = [tableView dequeueReusableCellWithIdentifier:@"questionCell2" forIndexPath:indexPath];
            
            if (cell==nil) {
                
                cell=[tableView dequeueReusableCellWithIdentifier:@"questionCell2"];
            }
            
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            UIView *backView = (UIView *)[cell.contentView viewWithTag:1];
            backView.backgroundColor = [UIColor whiteColor];
            
            
            
            NSLog(@"questionDic -- %@",questionDic);
            UILabel*label1=(UILabel*)[cell.contentView viewWithTag:111];
            label1.text = @"188***21";
            label1.text = [questionDic objectForKey:@"name"];
            
            //           reply introduce
            UILabel*label2=(UILabel*)[cell.contentView viewWithTag:222];
            label2.text = @"问题";
            label2.text = [questionDic objectForKey:@"introduce"];
            NSLog(@"[questionDic objectForKey:@introduce]%@",[questionDic objectForKey:@"introduce"]);
            label2.numberOfLines = 0;
            [label2 sizeToFit];
            
            
//            UILabel*label4=(UILabel*)[cell.contentView viewWithTag:555];
//            label4.text = @"回答";
//            label4.text = [questionDic objectForKey:@"reply"];
//            label4.numberOfLines = 0;
//            [label4 sizeToFit];
//            NSLog(@"[questionDic objectForKey:@reply]%@",[questionDic objectForKey:@"reply"]);
            
            UILabel*label3=(UILabel*)[cell.contentView viewWithTag:333];
            label3.text = @"2015-1-12";
            
//            UILabel*label5=(UILabel*)[cell.contentView viewWithTag:666];
//            label5.text = @"2015-1-12";
            
            NSString *timeString = [questionDic objectForKey:@"addtime"];
            
            NSLog(@"timeString -- %@",timeString);
            //得到运动时间，需要转成年月日
            NSString *formatString = @"YYYY-MM-dd";
            
            NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
            [dateFormat setDateFormat:formatString];
            NSDate*confromTimesp = [NSDate dateWithTimeIntervalSince1970:(NSTimeInterval)[timeString intValue] - 28800];
            NSString *dateString =[NSString stringWithFormat:@"%@",[dateFormat stringFromDate:confromTimesp] ];
            NSLog(@"date: %@", dateString);
            
            label3.text = dateString;
//            label5.text = dateString;
            
            return cell;

        }
        
        
        
        
        return cell;
        
    }
    
    
    //    }
    else if (indexPath.section == 4){
        
        cell.userInteractionEnabled = YES;
        cell = [tableView dequeueReusableCellWithIdentifier:@"baoMingCell" forIndexPath:indexPath];
        
        if (cell==nil) {
            
            cell=[tableView dequeueReusableCellWithIdentifier:@"baoMingCell"];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        
        UIButton *baoButton = (UIButton *)[cell.contentView viewWithTag:11011];
        [baoButton addTarget:self action:@selector(pushToBaoMin) forControlEvents:UIControlEventTouchUpInside];
        [baoButton setBackgroundColor:UIColorFromRGB(0xff8637)];
//        baoButton.titleLabel.text = @"我要报名";
        
        
        //        [cell.contentView addSubview:baoButton];
        
        
       
        
        return cell;
    }
    
    cell.backgroundColor = UIColorFromRGB(0xf5f5f5);
    
    
    return cell;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //    indexPath.row;
    //    [tableView deselectRowAtIndexPath:indexPath animated:NO];//点击后不会有阴影
    
    if (indexPath.section == 2) {
        NSLog(@"sb");
    }
    
    
    
}

//去报名界面
- (void)pushToBaoMin{
    
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    self.navigationController.navigationBar.alpha=1;
    if ([self.title isEqualToString:@"论坛"] || [self.title isEqualToString:@"游学"] || [self.title isEqualToString:@"创投"]) {
        
        self.hidesBottomBarWhenPushed = YES;
        [self performSegueWithIdentifier:@"luntanAndTourStudyIdentifier" sender:nil];
    }
    
    else {
        self.hidesBottomBarWhenPushed = YES;
        [self performSegueWithIdentifier:@"PushZiXunBaoMin" sender:nil];
        
    }
    
}

//问题事件
- (void)questionEvent{
    
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    self.navigationController.navigationBar.alpha=1;
    
    self.hidesBottomBarWhenPushed = YES;
    [self performSegueWithIdentifier:@"goToAskQuestion" sender:nil];
}


//手写的按钮
- (void)WriteBaoMin{

    [self.navigationController setNavigationBarHidden:NO animated:YES];
    self.navigationController.navigationBar.alpha=1;
    if (IFUserLogin) {
        
        if ([self.title isEqualToString:@"咨询"]) {
            self.hidesBottomBarWhenPushed = YES;
            [self.navigationController setNavigationBarHidden:NO animated:YES];
            [self performSegueWithIdentifier:@"goToZiXunBaoMin" sender:nil];
            return;
        }
        
        
        NSString *groupid = [[UserDefaults objectForKey:@"user"] objectForKey:@"groupid"];
        NSLog(@"groupid-+*%@",groupid);
        NSLog(@"baoMinString-+*%@",baoMinString);
        if (baoMinString.length > 0) {
            
            //如果自己在这个可以观看的组里面
        if ([baoMinString isEqualToString:[[UserDefaults objectForKey:@"user"] objectForKey:@"groupid"] ]) {
            
            if ([self.title isEqualToString:@"论坛"] || [self.title isEqualToString:@"游学"]) {
                self.hidesBottomBarWhenPushed = YES;
                [self performSegueWithIdentifier:@"youxueAndLuntanBaoMin" sender:nil];//youxueAndLuntanBaoMin   goToluntanAndTourStudy
            }
            
            else if ([self.title isEqualToString:@"创投"]){
                self.hidesBottomBarWhenPushed = YES;
                [self performSegueWithIdentifier:@"chuangtouBaoMin" sender:nil];
            }
            
            else {
                self.hidesBottomBarWhenPushed = YES;
                [self performSegueWithIdentifier:@"goToZiXunBaoMin" sender:nil];
                
            }
            
        }
        else{
            [SVProgressHUD showSuccessWithStatus:@"您没有报名权限。"];
        }
        
    }
        
        //没有点击区分观看者
        else{
            if ([self.title isEqualToString:@"论坛"] || [self.title isEqualToString:@"游学"] ) {
                self.hidesBottomBarWhenPushed = YES;
                [self performSegueWithIdentifier:@"youxueAndLuntanBaoMin" sender:nil];//youxueAndLuntanBaoMin   goToluntanAndTourStudy
            }
            
            else if ([self.title isEqualToString:@"创投"]){
                self.hidesBottomBarWhenPushed = YES;
                [self performSegueWithIdentifier:@"chuangtouBaoMin" sender:nil];
            }
            
            else {
                self.hidesBottomBarWhenPushed = YES;
                [self performSegueWithIdentifier:@"goToZiXunBaoMin" sender:nil];
                
            }
        }
         }
    
    //没有登录，跳转到登录界面
    else{
        UIStoryboard*story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
        LoginViewController*login=[story instantiateViewControllerWithIdentifier:@"LoginViewController"];
        UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:login];
        //        [self.navigationController pushViewController:login animated:YES];
        
        [self presentViewController:nav animated:YES completion:nil];
    }
    

}

- (IBAction)baoMin:(id)sender {
    
//    if (IFUserLogin) {
//        
//        if ([baoMinString isEqualToString:[[UserDefaults objectForKey:@"user"] objectForKey:@"groupid"] ]) {
//            if ([self.title isEqualToString:@"论坛"] || [self.title isEqualToString:@"游学"] || [self.title isEqualToString:@"创投"]) {
//                self.hidesBottomBarWhenPushed = YES;
//                [self performSegueWithIdentifier:@"goToluntanAndTourStudy" sender:nil];
//            }
//            
//            else {
//                self.hidesBottomBarWhenPushed = YES;
//                [self performSegueWithIdentifier:@"goToZiXunBaoMin" sender:nil];
//                
//            }
//
//        }
//        else{
//        [SVProgressHUD showSuccessWithStatus:@"您没有报名权限。"];
//        }
//        
//    }
//    
//    //没有登录，跳转到登录界面
//    else{
//        UIStoryboard*story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
//        LoginViewController*login=[story instantiateViewControllerWithIdentifier:@"LoginViewController"];
//        UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:login];
//        //        [self.navigationController pushViewController:login animated:YES];
//        
//        [self presentViewController:nav animated:YES completion:nil];
//    }
    

    if ([IWantButton.titleLabel.text isEqualToString:@"已结束"]) {
        return;
    }
    
    [self WriteBaoMin];

}


-(void)popOfDismss{
    
//        [self goBack];
        [self.navigationController popViewControllerAnimated:YES];
    
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    self.navigationController.navigationBar.alpha=1;
}
- (IBAction)goBBack:(id)sender {
    [self popOfDismss];
}
- (IBAction)goBack:(id)sender {
    
    [self popOfDismss];
}
- (IBAction)goBackTo:(id)sender {
    [self popOfDismss];
}

- (IBAction)writeQuestion:(id)sender {
    [self questionEvent];
    
}

- (IBAction)shareTheView:(id)sender {
    [self rightBarButtonClicked];
}

- (void)viewDidUnload{

  

    [super viewDidUnload];
}




/** 正在滚动，控制滚动的时候一些控件的显示和消失 */
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    NSLog(@"scrollView %@",scrollView);
    NSLog(@"contentOffset x %f y %f",scrollView.contentOffset.x,scrollView.contentOffset.y );
    NSLog(@"contentOffset w %f h %f",scrollView.contentSize.width,scrollView.contentSize.height);
    NSLog(@"contentOffset l %f r %f",scrollView.contentInset.left,scrollView.contentInset.right);
    
    NSLog(@"scrollView.contentSize.height - scrollView.contentOffset.y =%f",scrollView.contentSize.height - scrollView.contentOffset.y - self.view.frame.size.height);
    
    float nowHeight = scrollView.contentSize.height - scrollView.contentOffset.y - self.view.frame.size.height + scrollView.frame.origin.y;
    
    if (nowHeight <= 100  && nowHeight >= 0) {
        NSLog(@"nowHeight =%f",nowHeight);
        float alo = nowHeight / 100;
        CGFloat value = ABS(nowHeight / 100);
        CGFloat scaleLeft = 1 - value;
        
        NSLog(@"scaleLeft =%f",scaleLeft);
        BlackBackButton.alpha = scaleLeft;
        IWantButton.alpha = scaleLeft;
        smallShareButton.alpha = scaleLeft;
        smallAskQuBut.alpha = scaleLeft;
        
        
        
        

        
        BlackBackButton.userInteractionEnabled = YES;
        IWantButton.userInteractionEnabled = YES;
        smallShareButton.userInteractionEnabled = YES;
        smallAskQuBut.userInteractionEnabled = YES;
    }
    else if(nowHeight > 100){
        BlackBackButton.alpha = 0;
        IWantButton.alpha = 0;
        smallShareButton.alpha = 0;
        smallAskQuBut.alpha = 0;
        
        
        BlackBackButton.userInteractionEnabled = NO;
        IWantButton.userInteractionEnabled = NO;
        smallShareButton.userInteractionEnabled = NO;
        smallAskQuBut.userInteractionEnabled = NO;
    }
    
    // 取出绝对值 避免最左边往右拉时形变超过1
//    CGFloat value = ABS(scrollView.contentOffset.x / scrollView.frame.size.width);
//    NSUInteger leftIndex = (int)value;
//    NSUInteger rightIndex = leftIndex + 1;
//    CGFloat scaleRight = value - leftIndex;
//    CGFloat scaleLeft = 1 - scaleRight;
//    SXTitleLable *labelLeft = self.smallScrollView.subviews[leftIndex];
//    labelLeft.scale = scaleLeft;
//    //左边变大变红，右边就变小变黑。左边变小变黑，右边就变大变红。
//    // 考虑到最后一个板块，如果右边已经没有板块了 就不在下面赋值scale了
//    if (rightIndex < self.smallScrollView.subviews.count) {
//        SXTitleLable *labelRight = self.smallScrollView.subviews[rightIndex];
//        labelRight.scale = scaleRight;
//    }
    
    
    NSLog(@"study = %@",studyCell);
 
 
    
 
        if (scrollView.contentOffset.y > 0 && scrollView.contentOffset.y < 122) {
            CGFloat value = ABS(scrollView.contentOffset.y / 122);
            CGFloat scaleLeft = 1 - value;
            NSLog(@"cell alpha == %f",scaleLeft);
//            studyCell.alpha = scaleLeft;
//            headImage.alpha = scaleLeft;
//            BigTitleLabel.alpha = scaleLeft;
//            SmaTitleLabel.alpha = scaleLeft;
//            IWantBut.alpha = scaleLeft;
        }
    
 
    if (scrollView.contentOffset.y < 0 && scrollView.contentOffset.y > -200) {
        
        float backImageView = 1 - (scrollView.contentOffset.y / 200);
        CGAffineTransform newTRansform = CGAffineTransformMakeScale(backImageView, backImageView);
        [backImage setTransform:newTRansform];//照片的放大和缩小
    
    }
    
}
@end
